package com.controller;

import com.github.pagehelper.PageInfo;
import com.pojo.Client;
import com.service.ClientService;
import com.vo.QueryVo;
import com.vo.ResultVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping ("/client")
@ResponseBody
public class ClientController {
    
    @Resource
    private ClientService clientService;
    
    @RequestMapping(value = "list" , method = RequestMethod.GET)
    public ResultVo<Client> queryByPage(Integer pageNum , Integer pageSize , QueryVo vo){
        PageInfo<Client> list = clientService.queryByPage(pageNum , pageSize , vo);
        return new ResultVo<>(list);
    }
    
    @RequestMapping(value = "{c_num}" , method = RequestMethod.GET)
    public ResultVo<Client> queryByKey(@PathVariable("c_num") Integer c_num){
        return new ResultVo<>(clientService.queryByKey(c_num));
    }
    
    @RequestMapping(value = "" , method = RequestMethod.POST)
    public ResultVo<Client> add(Client client){
        int add = clientService.add(client);
        if (add == 0){
            return new ResultVo<>(500,"服务器异常！");
        }
        return new ResultVo<>();
    }
    
    @RequestMapping(value = "{c_num}")
    public ResultVo<Client> del(@PathVariable ("c_num") Integer c_num){
        int del = clientService.del(c_num);
        if (del == 0) {
            new ResultVo<>(500,"服务器异常!");
        }
        return new ResultVo<>();
    }
    
    @RequestMapping(value = "" , method = RequestMethod.PUT)
    public ResultVo<Client> update(Client client){
        int update = clientService.update(client);
        if (update == 0){
            new ResultVo<>(500 , "服务器异常！");
        }
        return new ResultVo<>();
    }
    
}
